package config

import (
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/layout"
	"fyne.io/fyne/v2/widget"
	log "github.com/sirupsen/logrus"
)

var ZuoJieGou = leftStructure()

var data = map[string][]string{
	"":      {"数据库配置", "其他"}, //根节点
	"数据库配置": {"mysql", "oracle"},
	//"其他": {"川菜", "粤菜"},
}

func leftStructure() fyne.CanvasObject {
	//创建一个树形控件
	tree := widget.NewTreeWithStrings(data)
	tree.OpenAllBranches() //展开所有
	//监听选择事件
	tree.OnSelected = func(uid widget.TreeNodeID) {
		changeCenterJieGou(uid)
	}
	return container.New(layout.NewStackLayout(), tree)
}

// 切换CenterJieGou的内容  通过uid widget.TreeNodeID识别
func changeCenterJieGou(uid widget.TreeNodeID) {
	switch uid {
	case "mysql":
		//切换到ApiFox
		err := YouCenterBody.Set("MysqlConfig")
		if err != nil {
			log.Error(err)
			return
		}
	case "oracle":
		err := YouCenterBody.Set("OracleConfig")
		if err != nil {
			log.Error(err)
			return
		}
	case "其他":
		//切换到其他
		err := YouCenterBody.Set("OtherConfig")
		if err != nil {
			log.Error(err)
			return
		}
	}
}
